<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>fetch_push</title>

</head>

<body>
    <input type="text">
    <span></span>
    <script>
        let input = document.querySelector("input");
        let span = document.querySelector("span");
        input.onchange = () => {
            fetch("https://mock.mengxuegu.com/mock/6673cc1fbe17764121dfc577/ajax/phone",{
                method:"post",
                headers:{
                    "Content-Type":"application/x-www-form-urlencoded"
                },
                body:"phone="+input.value
            } ).then(res => res.json())
                .then(res => {
                    console.log(res);
                    if (res.data.code === 10001) {
                        span.innerText = "手机号已注册，无法使用";
                    } else {
                        span.innerText = "手机号未注册，可以使用";
                    }

                })
        }
    </script>
</body>

</html>